<template>
	<div class="me_content">
		<MeInfo @getUserInfoComplete="meInfoGetComplete"></MeInfo>
		<div class="luo_bottom_bg">
			<!-- item.isTestCount && item.isTestCount > 0 && -->
			<div v-bind:class="['luo_bottom_item' ,item.isServiceShow == 0 ? 'luo_me_hidden':'']" v-for="(item,index) in titles" @click="titleAction(item)">
				<span class="luo_bottom_item_top_bg">
					<img class="luo_bottom_item_img" v-bind:src="item.img" />
					<span class="luo_bottom_item_title">{{item.name}}</span>
				</span>
				<div class="luo_me_row_right">
					<span v-if="item.hint" v-bind:class="[(item.hintClass) ? item.hintClass:'']">{{item.hint}}</span>
					<img v-if="item.rightArrow" class="luo_bottom_item_row" src="../../resources/images/me/luo_row_right.png" />
				</div>
				
			</div>
		</div>
		<!-- <div class="test_button" @click="testBtnClick"></div> -->
	</div>
</template>

<script>
	import MeInfo from './MeInfo.vue'
	import HttpUtil from '../../js/HttpUtil.js'
	import UserInfoManager from "../../js/UserInfoManager.js"

	export default {
		components: {
			MeInfo
		},
		data() {
			return {
				test: 0,
				serviceInfo:{"status":0,"showLineStatus":0},
				titles: [
					{
						"name": "我的金币",
						"tag": 5,
						"hint": "0",
						"hintClass":"money",
						"img": require('../../resources/images/me/me_money.png')
					},
					{
						"name": "帮助与反馈1",
						"tag": 1,
						"img": require('../../resources/images/me/me_feedback.png'),
						"rightArrow":true
					},
					{
						"name": "隐私政策",
						"tag": 2,
						"img": require('../../resources/images/me/me_protocol.png'),
						"rightArrow":true
					},
					{
						"name": "关于我们",
						"tag": 3,
						"img": require('../../resources/images/me/me_about.png'),
						"rightArrow":true
					},
					{
						"name": "应用评价",
						"tag": 4,
						"img": require('../../resources/images/me/me_app_store_reviews.png'),
						"rightArrow":true
					},
					{
						"name": "切换线路",
						"tag": 0,
						"hint": "线路一",
						"img": require('../../resources/images/me/me_change_service.png'),
						"rightArrow":true,
						"isTestCount": 5 ,// 需要隐藏初始化值给5，代表点击5下显示
						"isServiceShow":0,//0隐藏 1显示
					}
				]
			}
		},
		mounted() {
			// 是否测试人员,是则显示切换按钮
			// var storage = window.localStorage;
			// let isTestUser = storage.getItem("curIsTestUserKey")
			// if (isTestUser == 1) {
			// 	console.log("是测试人员："+isTestUser)
			// 	let item = this.getChangeServiceItem()
			// 	item.isTestCount = 0
			// }else {
			// 	console.log("不是测试人员"+isTestUser)
			// }
			
			// console.log('curIndex:' + curIndex);
			this.refresServiceName()
			this.getUserAuthorization()
		},
		methods: {
			meInfoGetComplete:function() {
				let userInfo = UserInfoManager.getInfo()
				var coinCount = "0"
				if (userInfo.coinCount) {
					coinCount = ""+userInfo.coinCount
				}
				this.titles[0].hint= coinCount+" 金币"
				console.log("拿到用户金币值："+coinCount)
			},
			testBtnClick:function() {
				let item = this.getChangeServiceItem()
				if (item.isTestCount > 0) {
					item.isTestCount = item.isTestCount - 1
				}
				console.log(item.isTestCount)
				if (item.isTestCount == 0) {
					var storage = window.localStorage;
					let isTestUser = storage.getItem("curIsTestUserKey")
					console.log("是否测试人员："+isTestUser)
					if (isTestUser == 1) {// 已经是测试人员了，再点击则隐藏
						storage.setItem("curIsTestUserKey",0);
						item.isTestCount = 5
						console.log("隐藏")
					}else {
						console.log("显示")
						storage.setItem("curIsTestUserKey",1);
						item.isTestCount = 0
						
					}
					
				}
			},
			getChangeServiceItem:function(){
				let len = this.titles.length
				console.log("行数总长度："+len)
				for (var i= 0; i<len; i++) {
					console.log("行数总："+JSON.stringify(this.titles[i]))
					let curitem = this.titles[i]
					if (curitem) {
						console.log("当前item："+JSON.stringify(curitem))
					}
					
					if (curitem["name"] == "切换线路") {
						return curitem
					}
				}
				return null
			},
			refresServiceName: function() {
				let titem = this.getChangeServiceItem()
				if (HttpUtil.isAborad) {
					titem["hint"] = "线路一"
				} else {
					titem["hint"] = "线路二"
				}
			},
			titleAction: function(item) {
				switch (item.tag) {
					case 5:
						//我的金币
						console.log("点击金币");
						// alert("暂不支持")
						break;
					case 0:
						//反馈
						console.log("切换服务器");
						HttpUtil.changeService()
						this.refresServiceName()
						this.changServiceAndSyncUser()
						break;
					case 1:
						//反馈
						console.log("反馈");
						this.$router.push({
							path: '/Me/MeFeedback'
						})
						break;
					case 2:
						//隐私政策
						console.log("隐私政策");
						// window.location.href = "http://www.baidu.com";
						this.$router.push({
							path: '/Me/MePrivacyPolicy'
						})
						break;
					case 3:
						//隐私政策
						console.log("关于我们");
						// window.location.href = "http://www.baidu.com";
						this.$router.push({
							path: '/Me/MeAboutUs'
						})
						break;
					case 4:
						//应用评价
						console.log("应用评价");
						AppBridge.requestNativeGoAppStoreReviewsCmd003();
						break;
					default:
						break;
				}
			},
			changServiceAndSyncUser:function() {//切换服务器，同步用户数据
				let that = this;
				let sessionKey = UserInfoManager.getInfo().userExt.sessionKey
				var params = new URLSearchParams();
				params.append('sessionkey', sessionKey);
						
				HttpUtil.post('user/syncUserInfo.do', params)
					.then(response => {
						console.log(JSON.stringify(response.data));
						
						if (response.data.code == 0) {
							console.log("同步用户信息成功")
						}else {
							console.log("同步用户信息失败")
						}
					})
					.catch(function(error) {
						console.log(error);
					});
			},
			getUserAuthorization:function() {//获取用户权限
				let that = this;
				let sessionKey = UserInfoManager.getInfo().userExt.sessionKey
				var params = new URLSearchParams();
				params.append('sessionkey', sessionKey);
						
				HttpUtil.post('mobile/totalController.do', params)
					.then(response => {
						console.log(JSON.stringify(response.data));
						
						if (response.data.code == 0) {
							that.serviceInfo = response.data.data
							console.log("获取fw信息成功："+JSON.stringify(that.serviceInfo))
							if (that.serviceInfo.showLineStatus == 1) {
								let item = that.getChangeServiceItem()
								item.isServiceShow = 1
							}
						}else {
							console.log("获取fw信息失败")
						}
					})
					.catch(function(error) {
						console.log(error);
					});
			}
		}
	}
</script>

<style>
	/**luo添加**/
	.luo_bottom_bg {
		display: flex;
		flex-direction: column;
		margin-top: 10px;
		background-color: white;
		/* justify-content:flex-start; */

	}

	.luo_bottom_item {
		display: flex;
		flex-direction: row;
		justify-content: space-between;
		align-items: center;
		padding: 10px;

	}

	.luo_bottom_item_top_bg {
		display: flex;
		flex-direction: row;
		justify-content: space-between;
		align-items: center;
	}

	.luo_bottom_item_img {
		margin-left: 18px;
		width: 30px;
		height: 30px;
	}

	.luo_bottom_item_title {
		margin-left: 20px;
		color: #000000;
	}

	.luo_bottom_item_row {
		width: 20px;
		height: 20px;
		margin-right: 18px;
	}
	
	.luo_me_row_right {
		display: flex;
		flex-direction: row;
		align-content: center;
	}
	
	.luo_me_row_right span {
		line-height: 20px;
		color: #BEBEBE;
		margin-right: 5px;
	}
	
	.luo_me_row_right span.money {
		color: #f8914d;
	}
	
	.luo_me_hidden {
		display: none;
	}
	
	.test_button {
		/* opacity: 1; */
		height: 40px;
		width: 100%;
		/* background-color: red; */
	}

	/**end**/
</style>
